/*
 * CS_GUILD_KEY_UPDATE.cpp
 *
 *  Created on: 2014. 8. 1.
 *      Author: mega
 */

#include "../../User.h"
#include "../../Command.h"
#include "../../Proxy.h"

#include "../protocol/Guild.h"

namespace ProjectZ { namespace NCommand {

static void SendFail(User * pUser, int ack)
{
	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << static_cast<int16_t>(ack);
	pAck->MakePacket(CMD_SC_GUILD_KEY_UPDATE);
	pUser->Send(pAck);
}

void Command::CS_GUILD_KEY_UPDATE(User * pUser, ::Network::Packet * pPacket)
{
/*	CS_GUILD_KEY_UPDATE						0x326C
	{
		u32			u32guild_seq;		//길드번호
		str			strPassword;		//길드 암호 (널일 경우는 암호 없음)
	}

	SC_GUILD_KEY_UPDATE						0x326D
	{
		s16			s16ack;				/// ACK_OK: 성공
										/// ACK_GUILD_PERMISSION_ERROR : 권한없음
	}*/

	PREPARE_PACKET;

	uint32_t guildSeq = 0;
	Toolkit::Str<10> password;

	*pPacket >> guildSeq >> password;

	if (0 >= pUser->GetUserInfo().guild_seq)
	{
		SendFail(pUser, ACK_UNKNOWN_ERROR);
		return;
	}

	UpdateGuildJoinPasswordSyn syn;
	syn.guild_seq	= pUser->GetUserInfo().guild_seq;
	syn.user_seq	= pUser->GetUserSeq();
	syn.password	= password.c_str();

	if (false == NProxy::SendGuildServer(pUser, syn))
	{
		SendFail(pUser, ACK_UNKNOWN_ERROR);
		return;
	}
}

} /*NCommand*/ } /*ProjectZ*/
